<?php

namespace App\Http\Controllers\admin;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

/**
 * 前台用户controller
 * Class UserController
 * @package App\Http\Controllers\admin
 */
class UserController extends Controller
{
    /**
     * 定义用户模型变量
     * @var
     */
    protected $userModel;

    /**
     * 实例化用户模型
     * UserController constructor.
     */
    public function __construct()
    {
        $this->userModel = new User();
    }

    /**
     * 显示用户列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(){
        return view('admin.user.index');
    }

    /**
     * 前台用户列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function getList(Request $request){
        $params = [
            'where'=>[
                ['disabled','1']
            ],
            'field'=>['id','username','email','image','mobile','sex','created_at','updated_at','ip','is_open','disabled'],
            'order'=>'created_at',
            'getfield'=>false,
            'page'=>$request->input('page')-1,
            'limit'=>$request->input('limit')
        ];
        $userRes = $this->userModel->getList($params);
        $arr=[];
        foreach ($userRes as $k=>$v){
            $arr[]=(array)$v;
        }
        return response()->json(array('code'=>0,'data'=>$arr ? $arr : []));
    }
}
